package cn.yunhe.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import cn.yunhe.controller.CalculatorAction;

public class CalculatorInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;

	public String intercept(ActionInvocation invocation) throws Exception {
		CalculatorAction ca = (CalculatorAction) invocation.getAction();
		ActionContext ac = invocation.getInvocationContext();
		@SuppressWarnings("unchecked")
		Map<String, Object> request = (Map<String, Object>) ac.get("request");
		if(invocation.getProxy().getMethod().toLowerCase().equals("div")&&ca.getParamB() == 0){
			request.put("msg", "除数不能为0");
			return "error";
		}else{
			return invocation.invoke();
		}
	}

}
